#include <queue>

using namespace std;

class MyStack 
{
public:
queue<int> store;
queue<int> temp;
    MyStack() 
    {
        
    }
    
    void push(int x) 
    {
        store.push(x);
    }
    
    int pop() 
    {
        if(store.size() != 1)
        {
            while (store.size() != 1)
            {
                temp.push(store.front());
                store.pop();
            }
        }
        int result = store.front();
        store.pop();

        while (!temp.empty())
        {
            int wire = temp.front();
            temp.pop();
            store.push(wire);
        }
        
        return result;
    }
    
    int top() 
    {
        if(store.size() != 1)
        {
            while (store.size() != 1)
            {
                temp.push(store.front());
                store.pop();
            }
        }
        int result = store.front();
        temp.push(store.front());
        store.pop();

        while (!temp.empty())
        {
            int wire = temp.front();
            temp.pop();
            store.push(wire);
        }
        
        return result;
    }
    
    bool empty() 
    {
        return store.empty();
    }
};
    
    /**
     * Your MyStack object will be instantiated and called as such:
     * MyStack* obj = new MyStack();
     * obj->push(x);
     * int param_2 = obj->pop();
     * int param_3 = obj->top();
     * bool param_4 = obj->empty();
     */